﻿// See https://aka.ms/new-console-template for more information
using static System.Console;

Title = "Foreach删除集合中的元素";


List<string> list
 = new List<string>() { "red", null, "black", "black", "blue", "yellow", "white" };



//foreach (var item in list)
//{
//    if ("black".Equals(item))
//    {
//        list.Remove(item);
//    }
//}


DeleteElement(list);

list.ForEach(p => WriteLine(p));


ReadKey();


void DeleteElement(List<string> list)
{
    foreach (var item in list)
    {
        if ("black".Equals(item))
        {
            list.Remove(item);
            DeleteElement(list);
            return;
        }
    }
}
